
clear all
set more off

use "data/raw/defund-hypothetical-deidentified", clear 

* Classify private support
gen join = defunding_opposition=="Yes"
lab var join "Joined campaign"

* Drop pre-randomization attritters and flag post-randomization attriters
* condition: excuse or noexcuse
drop if !inlist(condition, "excuse", "noexcuse")

gen attrit = 0
replace attrit = 1 if defunding_opposition == "" | (defunding_opposition == "Yes" & post == "")
lab var attrit "Respondent attritted post-randomization"


* checked: screener13 is allExtremely interested; screener17 is Not at all interested
drop if attention != "1"

* Generate outcome and treatment variables
gen posted = post=="Yes"
replace posted = . if missing(post)
lab var posted "Authorized Twitter post"
drop post 

gen excuse = condition=="excuse"
lab var excuse "Excuse condition"
gen noexcuse = condition=="noexcuse"
lab var noexcuse "No excuse condition"
drop condition

* Generate demographic and control variables
gen ind = party=="Independent"
lab var ind "Independent"
drop party

gen partisan = .
replace partisan = 2 if liberal == "Very conservative"
replace partisan = 1 if liberal == "Conservative"
replace partisan = 0 if liberal == "Neither liberal nor conservative"
replace partisan = -1 if liberal == "Liberal"
replace partisan = -2 if liberal == "Very liberal"
label var partisan "Partisan leaning"


destring year, replace
gen age = 2022-year
lab var age "Age"
drop year

gen age2 = age^2
lab var age2 "Age squared"
gen hisp = hispanic=="Yes"
lab var hisp "Spanish, Hispanic, or Latino"
drop hispanic
gen male = sex == "Male"
lab var male "Male"
drop sex

lab var education "Education level"

gen white = race=="Caucasian/White"
lab var white "White"
lab var race "Race"


destring sob_1, replace
rename sob_1 sob

keep socialmedia vote sob credibility attrit  join posted excuse noexcuse education race ind partisan age age2 hisp male white 


save "data/working/defund-hypothetical.dta", replace
exit,clear
